<template>
  <div class="box">
    <div class="header">
      <van-nav-bar title="首页" >
         <template #left>
          <van-icon name="bars" size="20" />
        </template>
        <template #right>
          <van-icon name="search" size="20" />
        </template>
      </van-nav-bar>
    </div>
    <div class="content">
        <!-- 商品列表 -->
         <ul>
             <li v-for="item in list" :key="item.id" @click="$router.push('/detail/'+item.id)">
                 <div><img :src="item.image" alt=""></div>
                 <div>
                    <p  class="van-multi-ellipsis--l2">{{item.title}}</p>
                    <p style="color:red;">￥{{item.price}}</p>
                 </div>
             </li>
         </ul>
  <!-- 骨架屏 -->
         <van-skeleton>
  <template #template>
    <div :style="{ display: 'flex', width: '100%' }">
      <van-skeleton-image />
      <div :style="{ flex: 1, marginLeft: '16px' }">
        <van-skeleton-paragraph row-width="60%" />
        <van-skeleton-paragraph />
        <van-skeleton-paragraph />
        <van-skeleton-paragraph />
      </div>
    </div>
  </template>
</van-skeleton>
    </div>
  </div>
</template>

<script setup>
import request from '@/utils/request'
import {ref,onMounted} from 'vue'
const list = ref([])
onMounted(()=>{
    //请求列表
    request.get('/list').then(res=>{
        if(res.data.code==200)
        {
            list.value=res.data.data
        }
    })
})
</script>

<style lang="scss" scoped>
ul{
    column-count: 2;
    column-gap: 10px;
    li{
        break-inside: avoid;
        img{
            width: 100%;
        }
    }
}
</style>